package com.yuyang.gulimall.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yu yang
 * @date 2023/1/5 -21:07
 */
@Configuration
public class  ElasticSearchConfig {

    public static final RequestOptions COMMON_OPTIONS;
    @Value("${es.restClientHost}")
    public String restClientHost = "192.168.56.10";
    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
//        builder.addHeader("Authorization", "Bearer " + TOKEN);
//        builder.setHttpAsyncResponseConsumerFactory(
//                new HttpAsyncResponseConsumerFactory
//                        .HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024));
        COMMON_OPTIONS = builder.build();
    }
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        //RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost("192.168.56.10",9200));
        RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(restClientHost,9200));
        return new RestHighLevelClient(restClientBuilder);
    }
}